package com.djl.rabbitmq.six;

import com.djl.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @program: rabbitmq-hello
 * @description:
 * @author: Mr.dai
 * @create: 2021-09-12 16:07
 **/

public class ReceiveLogsDirect02 {
    public static final String EXCHANGE_NAME ="direct_log";

    public static void main(String[] args) throws Exception {
        //获取信道
        Channel channel = RabbitMqUtils.getChannel();
        //声明直接交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个队列
        channel.queueDeclare("disk",false,false,false,null);
        //绑定队列与交换机
        channel.queueBind("disk",EXCHANGE_NAME,"error");
        System.out.println("等待接收消息，把接收到的消息打印到屏幕上。。。。");
        //
        DeliverCallback deliverCallback=(consumerTag, message)->{
            System.out.println("ReceiveLogsDirect01接收控制台打印接收到的消息："+new String(message.getBody(),"UTF-8"));
        };
        channel.basicConsume("disk",true,deliverCallback,consumerTag->{});

    }
}
